<template>
  <div class="antv-chart-mini">
    <div class="chart-wrapper" :style="{ height: 46 }">
      <v-chart :force-fit="true" :height="height" :data="data" :padding="[36, 0, 18, 0]">
        <!-- <v-tooltip /> -->
        <v-smooth-area position="x*y" />
      </v-chart>
    </div>
  </div>
</template>

<script>
import moment from 'moment'
const data = []
// const beginDay = new Date().getTime()

// for (let i = 0; i < 10; i++) {
//   data.push({
//     x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY-MM-DD HH:mm:ss'),
//     y: Math.round(Math.random() * 10)
//   })
// }

const tooltip = [
  'x*y',
  (x, y) => ({
    name: x,
    value: y
  })
]
const scale = [{
  dataKey: 'x',
  min: 2
}, {
  dataKey: 'y',
  title: '时间',
  min: 1,
  max: 22
}]

export default {
  props: ['val'],
  name: 'MiniArea',
  data () {
    return {
      data,
      tooltip,
      scale,
      x: new Date().getTime() / 1000,
      height: 100
    }
  },
  watch: {
      val () {
        // console.log(this.val)
        this.setVal(this.val)
      }
  },
  methods: {
     setVal (value) {
       data.push({
         x: this.x += 1000,
         y: (parseFloat(value.replace('%', '')) * 100)
       })
       if (data.length > 60) {
          const num = data.length - 60
          data.splice(0, num)
       }
       // console.log(data)
     }
  }
}
</script>

<style lang="less" scoped>
  @import "chart";
</style>
